#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2018/12/6 9:17
# @Author  : lizhen
# @Site    : 
# @File    : tcpserver.py
# @Software: PyCharm
from socket import socket


def tcp_server():
    sock = socket()
    sock.bind(('', 8000))
    sock.listen(20)
    print('Server starts!')
    while True:
        new_sock, client_addr = sock.accept()
        data = new_sock.recv(1024)
        print('{}:{}'.format(client_addr, data.decode()))
        new_sock.send(data)


def main():
    tcp_server()


if __name__ == '__main__':
    main()
